// 顶升详情

<template>
  <f7-page class="detail">
    <f7-navbar>
      <f7-nav-left>
        <f7-link back icon-material="arrow_back" force></f7-link>
      </f7-nav-left>
      <f7-nav-title>顶升详情</f7-nav-title>
      <f7-nav-right></f7-nav-right>
    </f7-navbar>
    <div class="content-box">
        <img :src="require(`../../../../assets/img/qzjx/${notifyInfo.property.equipmentType||'TSQZJ'}.png`)" alt="" class="left-box">
        <div class="right-box">
            <div class="title-box">
              <section>
                <h3>{{notifyInfo.property.propertyCode||'--'}}</h3>
                <span class="tag tag-fill">自编号：{{installNotify.workSiteCode}}</span>
              </section>
              <!-- <img src="@/assets/img/qzjx/offLine.png" alt="" v-if="offlineWorkModel&&offlineWorkModel.pstatus==2"> -->
            </div>
            <p>{{notifyInfo.engineeBaseInfo.engineeName||'--'}}</p>
            <p>顶升单位：{{notifyInfo.installOrg.enterpriseName||'--'}}</p>
            <p>计划作业日期：<span>{{notifyInfo.workPlanDate|date('yyyy-MM-dd')}}</span></p>
            <span class="btns" @click="offlineWork" v-if="isConOrg||(!isConOrg&&offlineWorkModel&&offlineWorkModel.id)"><van-icon name="edit" />离线作业申请</span>
        </div>
    </div>
    <div class="tips-blue" v-if="showTips && workPlanTimeInfo && workPlanTimeInfo.finalWorkDate">
      <van-icon name="info-o" size="14px"/>
      <span v-if="workPlanTimeInfo.isOverdue">该设备已超过作业计划有效期，请在电脑端重新制定作业计划</span>
      <span v-else>请务必在{{ workPlanTimeInfo.finalWorkDate | date("yyyy年MM月dd日") }}之前完成本次安装作业。若{{ workPlanTimeInfo.remainDays }}天后仍未完成，本次上传的作业内容将视为无效，需重新制定作业计划。</span>
      <van-icon name="cross" size="12px" @click="showTips = false"/>
    </div>
    <div class="qzjx-card">
      <van-steps direction="vertical" :active="activeStep">
        <van-step v-for="(item,index) in installNoteList" :key="item.caseId" @click.native="canGo(item,index)?goDetail(item):''">
          <template v-slot:inactive-icon>
            <van-icon name="success" class="is-success" v-if="item.status==2"/>
            <div class="is-waiting" v-if="item.status==0"></div>
            <div class="is-process" v-if="item.status==1"></div>
            <div class="is-cancel" v-if="item.status==999"></div>
          </template>
          <template v-slot:active-icon>
              <van-icon name="success" class="is-success" v-if="item.status==2"/>
              <div class="is-process" v-if="item.status==0||item.status==1"></div>
              <div class="is-cancel" v-if="item.status==999"></div>
          </template>
          <div class="step-box">
            <!-- <span :class="{red:item.status==888}">{{item.nodeName}} <span class="tag tag-fill" v-if="item.desc">{{item.desc}}</span></span> -->
            <span>{{item.nodeName}} <span class="tag tag-fill" v-if="item.desc">{{item.desc}}</span></span>
            <span>{{item.caseStatusName}}<van-icon name="arrow" v-if="canGo(item,index)"/></span>
          </div>
        </van-step>
      </van-steps>
    </div>
  </f7-page>
</template>

<script>
import Config from "@/libs/config";
import Controller from "@/libs/framework/controller";
export default class sInsp extends Controller {
  onBeforeInit() {
    this.urls = {
      model: "/equipment/eqmUpNotify/queryUpManageInfo",
    };
  }
  onInit(){}
  onBeforeQuery(type, conditions, params) {
    this.vm.$f7.preloader.show();
  }
  onAfterQuery(type, isSuccess, result) {
    if(!isSuccess){
      setTimeout(() => {
        this.vm.$f7.preloader.hide();
        this.vm.$f7.dialog.alert('数据加载失败，请刷新页面重试')
      }, 3000);
    }
    this.$data.installNoteList=result.parameters.upNoteList||[]
    this.$data.notifyInfo=result.parameters.notifyInfo||{}
    this.$data.installNotify=result.parameters.upNotify||{}
    this.$data.workPlanTimeInfo=result.parameters.workPlanTimeInfo||{}
    this.$data.notifyId=result.parameters.notifyId
    this.$data.isConOrg=result.parameters.isConOrg
    this.$data.offlineWorkModel=result.parameters.offlineWork
    if(!this.$data.notifyInfo.property)this.$data.notifyInfo.property={}
    if(!this.$data.notifyInfo.engineeBaseInfo)this.$data.notifyInfo.engineeBaseInfo={}
    if(!this.$data.notifyInfo.installOrg)this.$data.notifyInfo.installOrg={}
    this.vm.$f7.preloader.hide();
    this.vm.getStep()
    return result;
  }

  mixin() {
    return {
      props: {},
      data() {
        return {
          notifyInfo: {
            property:{},
            engineeBaseInfo:{},
            installOrg:{}
          },
          workPlanTimeInfo:{},
          installNoteList:[],
          activeStep:0,
          installNotify:{},
          notifyId:'',
          isConOrg:false,
          offlineWorkModel:{},
          showTips:true
        };
      },
      computed: {},
      methods: {
        offlineWork(){
          if(this.offlineWorkModel&&this.offlineWorkModel.id){
            this.$f7.preloader.show();
              this.$framework.util
                .getPromise(`/app/workflow/getWorkflowArgs`, { formId: this.offlineWorkModel.id })
                .then(res => {
                  if (!res.pageAction || !res.assigneeId) {
                    this.$f7.preloader.hide();
                    return;
                  }
                  let url=res.mobileFormUrl
                  const params = {
                    pageAction: res.pageAction,
                    assigneeId: res.assigneeId,
                    notifyId:this.notifyId,
                    action:res.pageAction=='edit'?'processEdit':'processView',
                    version:res.version,
                    formId:this.offlineWorkModel.id
                  };
    
                  if (res.pageAction === 'view') {
                    Object.assign(params, { historyTaskId: res.historyTaskId })
                  } else {
                    Object.assign(params, { taskId: res.taskId })
                  }
                  let paramStr = [];
                  for (let key in params) {
                    paramStr.push(`${key}=${params[key]}`);
                  }
                  paramStr = paramStr.join("&");
                  this.$f7.view.current.router.navigate(url+`?${paramStr}`);
                })
                .catch(err => {
                  this.$f7.preloader.hide();
                })
                .finally(() => {});
          }else{
            this.$f7.view.current.router.navigate(`/business/qzjx/offlineWork/index?notifyId=${this.notifyId}&action=processStart&pageAction=create`);
          }
        },
        canGo(item,index){
          if(this.activeStep>=index){
            if(item.nodeType!='UP_NOTIFY'&&item.nodeType!='WORK_PLAN'&&!item.caseId){
              let code=''
              switch (item.nodeType) {
                case 'UP_BEFORE_CHECK': // 顶升前检查
                  code='equipment:eqmUpPrepare:add'
                  break;
                case 'UP_PROCESS': // 顶升过程/现场顶升
                  code='equipment:eqmUpProcess:add'
                  break;
                case 'UP_SELF_CHECK': // 顶升自检
                  code='equipment:eqmUpSelfCheck:add'
                  break;
                case 'UP_RECEIVE': // 顶升验收
                  code='equipment:eqmUpAcceptance:add'
                  break;
                default:
                  break;
              }
              console.log(this.$framework.account.hasPermission(code));
              if(this.$framework.account.hasPermission(code)){
                return true
              }else{
                return false
              }
            }else{
              return true
            }
          }else{
            return false
          }
          
        },
        // 详情
        goDetail(item) {
          // 计划作业时间后面的节点 如果作业已超期 且 状态是未完成 则不可以查看详情
          if(item.nodeType != 'UP_NOTIFY' && item.nodeType != 'WORK_PLAN' && this.workPlanTimeInfo.isOverdue && item.status != 2){
            return this.$f7.dialog.toast("该设备已超过作业计划有效期，请在电脑端重新制定作业计划");
          }
          let notifyId=this.notifyId||this.$f7route.query.notifyId
          let url=''
          switch (item.nodeType) {
            case 'UP_NOTIFY': // 顶升告知
              url='/business/qzjx/roofUp/notify'
              break;
            case 'WORK_PLAN': // 计划作业时间
              url='/business/qzjx/workPlan/index'
              break;
            case 'UP_BEFORE_CHECK': // 顶升前检查
              url='/business/qzjx/roofUp/beforeCheck'
              break;
            case 'UP_PROCESS': // 顶升过程/现场顶升
              url='/business/qzjx/roofUp/process'
              break;
            case 'STOP_WORK': // 中止作业
              url='/business/qzjx/workPlan/stopWork'
              break;
            case 'UP_SELF_CHECK': // 顶升自检
              url='/business/qzjx/roofUp/check'
              break;
            case 'UP_RECEIVE': // 顶升验收
              url='/business/qzjx/roofUp/receive'
              break;
            default:
              break;
          }
          if(item.caseId){
            if(item.nodeType=='UP_PROCESS'){
              this.$f7.view.current.router.navigate(url+`?pageAction=edit&caseId=${item.caseId}&notifyId=${notifyId}`);
            }else if(item.nodeType=='UP_SELF_CHECK'){
              this.$f7.view.current.router.navigate(url+`?pageAction=view&caseId=${item.caseId}&notifyId=${notifyId}`);
            }else{
              this.$f7.preloader.show();
              this.$framework.util
                .getPromise(`/app/workflow/getWorkflowArgs`, { formId: item.caseId })
                .then(res => {
                  if (!res.pageAction || !res.assigneeId) {
                    this.$f7.preloader.hide();
                    return;
                  }
                  const params = {
                    pageAction: res.pageAction,
                    caseId: item.caseId,
                    assigneeId: res.assigneeId,
                    notifyId,
                    action:res.pageAction=='edit'?'processEdit':'processView',
                    formId:item.caseId,// 用于获取流程数据
                  };
    
                  if (res.pageAction === 'view') {
                    Object.assign(params, { historyTaskId: res.historyTaskId })
                  } else {
                    Object.assign(params, { taskId: res.taskId })
                  }
                  let paramStr = [];
                  for (let key in params) {
                    paramStr.push(`${key}=${params[key]}`);
                  }
                  paramStr = paramStr.join("&");
                  this.$f7.view.current.router.navigate(url+`?${paramStr}`);
                })
                .catch(err => {
                  this.$f7.preloader.hide();
                })
                .finally(() => {});
            }
          }else{
            this.$f7.view.current.router.navigate(`${url}?notifyId=${notifyId}&action=processStart&pageAction=create`);
          }
          
        },
        getStep(){
          let num=0
          if(this.installNoteList.length>0){
            for (let i = 0; i < this.installNoteList.length; i++) {
              const element = this.installNoteList[i];
              if(element.status==0){
                break
              }else if(element.status==1){
                this.activeStep=i
              }else if(element.status==999){
                num++
                this.activeStep=i
              }else{
                if(num>0){
                  this.activeStep=i
                }else{
                  this.activeStep=i+1
                }
              }
            }
          }
        },
      },
      created() {},
      mounted() {},
      watch: {},
    };
  }
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/css/commonPage.less');
</style>
